package com.cardmanage.mapper;

import com.cardmanage.pojo.Card;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CardMapper {
    @Select("SELECT id, name, telephone, email, company, post, address, logo_name, user_id " +
            "FROM card " +
            "WHERE id = #{id} AND user_id = #{userId}")
    Card GetOne(Integer id, Integer userId);
    @Select("SELECT id, name, telephone, email, company, post, address, logo_name, user_id " +
            "FROM card " +
            "WHERE user_id = #{userId}")
    List<Card> GetAll(Integer userId);
    @Insert("INSERT INTO card (name, telephone, email, company, post, address, logo_name, user_id) " +
            "VALUES (#{name}, #{telephone}, #{email}, #{company}, #{post}, #{address}, #{logoName}, #{userId})")
    void create(String name, String telephone, String email, String company, String post, String address, String logoName, Integer userId);

    void update(String name, String telephone, String email, String company, String post, String address, String logoName, Integer userId, Integer id);

    @Delete("DELETE FROM card WHERE user_id = #{userId} AND id = #{id}")
    void delete(Integer userId, Integer id);
}
